home *** CD-ROM | disk | FTP | other *** search
/ Kellogg's Amérique / Kellogg's Amérique / amazonie_en_danger.swf / scripts / jeux / Chrono.as next >
Text File  |  2020-08-04  |  3KB  |  150 lines

  1. package jeux
  2. {
  3.    import flash.display.MovieClip;
  4.    import flash.events.TimerEvent;
  5.    import flash.text.TextField;
  6.    import flash.utils.Timer;
  7.    
  8.    public class Chrono extends MovieClip
  9.    {
  10.        
  11.       
  12.       public var _laps:Number;
  13.       
  14.       public var secondes:TextField;
  15.       
  16.       const LAPS:Number = 1000;
  17.       
  18.       public var cpt_chrono:Timer;
  19.       
  20.       public var _temps:Number;
  21.       
  22.       public var sec:Number;
  23.       
  24.       public var min:Number;
  25.       
  26.       public var _sens:Boolean;
  27.       
  28.       const SENS:Boolean = true;
  29.       
  30.       public var fonction_fin:Function;
  31.       
  32.       public var minutes:TextField;
  33.       
  34.       public var _fin_chrono:Boolean;
  35.       
  36.       const TEMPS:Number = 120;
  37.       
  38.       public function Chrono()
  39.       {
  40.          super();
  41.          _temps = TEMPS;
  42.          _laps = LAPS;
  43.          _sens = SENS;
  44.          _fin_chrono = false;
  45.          cpt_chrono = new Timer(_laps,1);
  46.          cpt_chrono.addEventListener("timer",fin_laps);
  47.          minutes.embedFonts = true;
  48.          secondes.embedFonts = true;
  49.          afficher();
  50.       }
  51.       
  52.       public function lancer() : *
  53.       {
  54.          cpt_chrono.start();
  55.       }
  56.       
  57.       public function fin_laps(param1:TimerEvent) : *
  58.       {
  59.          if(_temps)
  60.          {
  61.             if(_sens)
  62.             {
  63.                --_temps;
  64.             }
  65.             else
  66.             {
  67.                ++_temps;
  68.             }
  69.             afficher();
  70.             cpt_chrono = new Timer(_laps,1);
  71.             cpt_chrono.start();
  72.             cpt_chrono.addEventListener("timer",fin_laps);
  73.          }
  74.          else
  75.          {
  76.             _fin_chrono = true;
  77.             trace("fin chrono ***");
  78.             if(fonction_fin != null)
  79.             {
  80.                fonction_fin();
  81.             }
  82.          }
  83.       }
  84.       
  85.       public function set temps(param1:Number) : *
  86.       {
  87.          _temps = param1;
  88.          afficher();
  89.       }
  90.       
  91.       public function get laps() : Number
  92.       {
  93.          return _laps;
  94.       }
  95.       
  96.       public function get temps() : Number
  97.       {
  98.          return _temps;
  99.       }
  100.       
  101.       public function set sens(param1:Boolean) : *
  102.       {
  103.          _sens = param1;
  104.       }
  105.       
  106.       public function get fin_chrono() : Boolean
  107.       {
  108.          return _fin_chrono;
  109.       }
  110.       
  111.       public function set laps(param1:Number) : *
  112.       {
  113.          _laps = param1;
  114.          cpt_chrono = new Timer(_laps,1);
  115.       }
  116.       
  117.       public function arreter() : *
  118.       {
  119.          cpt_chrono.stop();
  120.       }
  121.       
  122.       public function get sens() : Boolean
  123.       {
  124.          return _sens;
  125.       }
  126.       
  127.       public function afficher() : *
  128.       {
  129.          min = Math.floor(_temps / 60);
  130.          sec = _temps - min * 60;
  131.          if(min > 9)
  132.          {
  133.             minutes.text = min.toString();
  134.          }
  135.          else
  136.          {
  137.             minutes.text = "0" + min.toString();
  138.          }
  139.          if(sec > 9)
  140.          {
  141.             secondes.text = sec.toString();
  142.          }
  143.          else
  144.          {
  145.             secondes.text = "0" + sec.toString();
  146.          }
  147.       }
  148.    }
  149. }
  150.